<?php
/**
 * extention.func.php   用户自定义函数库
 *
 * @author           袁志蒙  
 * @license          http://www.yzmcms.com
 * @lastmodify       2018-03-18
 */

//获取配置项目
function get_setting($key=''){
	if(!$setting = getcache('setting')){
		$data = D('config')->where(array('type'=>99))->select();
		$setting = [];
		foreach($data as $val){
			$setting[$val['name']] = json_decode($val['setting'],true);
		}
		setcache('setting', $setting);
	}
    if(!$key){
		return $setting;
	}else{
		return array_key_exists($key, $setting) ? $setting[$key] : '';
	}	
}

//管理员列表
function get_admin($key=''){
	if(!$admin = getcache('admin')){
		$data = D('admin')->field('adminid,adminname')->where()->select();
		$admin = [];
		foreach($data as $val){
			$admin[$val['adminid']]['adminid'] = $val['adminid'];
			$admin[$val['adminid']]['adminname'] = $val['adminname'];
		}
		setcache('admin', $admin);
	}
    if(!$key){
		return $admin;
	}else{
		return array_key_exists($key, $admin) ? $admin[$key] : '';
	}	
}